package action;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.sql.*;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import po.User;
import po.UserDAO;

public class CQM_LookuserAction {
	
public String name;

public String getName() {
	return name;
}

public void setName(String name) {
	this.name = name;
}

public String execute() throws UnsupportedEncodingException, SQLException {
	 HttpServletResponse response = null; 
	 HttpServletRequest request = ServletActionContext.getRequest();
	 response = ServletActionContext.getResponse();   
	 request.setCharacterEncoding("utf-8");
	 response.setContentType("text/html;charset=utf-8");
		User user=new User(name+"@126.com");
	   List list=new UserDAO().findByExample(user);
	 
	
	if(list.size()>0){
		StringBuffer resultString=new StringBuffer("用户名已用");
	try {
		ServletActionContext.getResponse().getWriter().print(resultString.toString());
	} catch (IOException e) {
		
		e.printStackTrace();
	}
			
	}else{
		StringBuffer resultString=new StringBuffer("用户名可用");
	try {
		ServletActionContext.getResponse().getWriter().print(resultString.toString());
	} catch (IOException e) {
		
		e.printStackTrace();
	}
	}
	return null;
	 }

}
